import Vue from 'vue'
import store from '@/store'
import MinRequest from '@/utils/MinRequest'
import globalConfig from '@/config'

const minRequest = new MinRequest()

// 请求拦截器
minRequest.interceptors.request((request) => {

	return request;
})

// 响应拦截器
minRequest.interceptors.response((response) => {
	return response.data
})

// 设置默认配置
minRequest.setConfig((config) => {
	config.baseURL = globalConfig.baseUrl
	return config
})

export default {
	// 这里统一管理api请求
	apis: {
		//动态设置baseUrl
		setConfigUrl(url)
		{
			minRequest.setConfig((config) => {
				globalConfig.baseUrl="http://"+url+"/api/";
				config.baseURL = globalConfig.baseUrl;
				return config;
			});
		},
		UpLoadEntityFileUrl()
		{
			return globalConfig.upFileAddr+"ERP/File/UpdateAccessories?token="+Vue.prototype.$store.state.user?.AccessToken;
		},
		// 登录
		login(params) {
			return minRequest.post('ERP/ERPLogin/CheckUser', params);
		},
		//
		FindObject(params)//{"token":"","data":{"_entityid":"0","pkvalue":"0"}}
		{
			params.token=Vue.prototype.$store.state.user?.AccessToken;
			return minRequest.post('ERP/Factory/FindObject',params);
		},
		Find(params)//{"token":"","data":{"_entityid":"0","qualifier":"col>0","sort":"colname,colname","sortdir":"0,0","fetchlimit":"20"}
		{
			params.token=Vue.prototype.$store.state.user?.AccessToken;
			return minRequest.post('ERP/Factory/Find',params);
		},
		Delet(params)//{"token":"","data":{"_entityid":2270092,"ids":"1,2,3,4,5,6"}
		{
			params.token=Vue.prototype.$store.state.user?.AccessToken;
			return minRequest.post('ERP/Factory/Delete',params);
		},
		//获取单据的实体数据
		GetBillEntity(params)//{"token":"","data":{"_entityid":2270092,"_uimainid":100,"_pkvalue":168,"_childs":"2270093,2270094","_rels":"OrganizationID，RelaterOrgID"}
		{
			params.token=Vue.prototype.$store.state.user?.AccessToken;
			return minRequest.post('ERP/BillUI/GetBillEntity',params);
		},
		//删除单据的实体数据
		DelBillEntity(params)//{"token":"","data":{"_entityid":2270092,"_uimainid":100,"ids":"1,2,3,4"}
		{
			params.token=Vue.prototype.$store.state.user?.AccessToken;
			return minRequest.post('ERP/BillUI/Delete',params);
		},
		//保存单据实体
		SaveBillEntity(params)//{"token":"","data":{"_entityid":2270092,"_uimainid":100,"ID":0,"BillNO":"001","Description":"名称","_rows_2270093":[{"ID":123,"RecordNum":1,"MaterialID":1}],"_del_rows_2270093":[{"ID":1},{"ID":2}]}{"token":"","data":{"_entityid":2270092,"_uimainid":100,"ID":0,"BillNO":"001","Description":"名称","_rows_2270093":[{"ID":123,"RecordNum":1,"MaterialID":1}],"_del_rows_2270093":[{"ID":1},{"ID":2}]}
		{
			params.token=Vue.prototype.$store.state.user?.AccessToken;
			return minRequest.post('ERP/BillUI/Save',params);
		},
		//审核单据实体
		CheckBillEntity(params)//{"token":"","data":{"_entityid":2270086,"_uimainid":3000820,"_colid":1795,"ids":"1,2,3,4","Description":"审核意见","Name":"审核"}}
		{
			params.token=Vue.prototype.$store.state.user?.AccessToken;
			return minRequest.post('ERP/BillUI/Check',params);
		},
		//反审核单据实体
		UnCheckBillEntity(params)//{"token":"","data":{"_entityid":2270092,"_uimainid":100,"_colid":0,"ids":"1,2,3","Description":"审核意见","Name":"反审核"}}
		{
			params.token=Vue.prototype.$store.state.user?.AccessToken;
			return minRequest.post('ERP/BillUI/UnCheck',params);
		},
		//获取数据源DataTable
		GetDataTable(params)//{"token":"","data":{"_code": "M_SO_002","soid": "saleorderid"}
		{
			params.token=Vue.prototype.$store.state.user?.AccessToken;
			return minRequest.post('ERP/DataSource/GetDataTable',params);
		},
		//获取附件列表
		GetAccessoriesUrls(params) {
			//{"Status":"状态码","Message":"信息","Data":[{"accentryid":1,"alisename":"文件名","filename":"路径","url":"文件url"}]}
			return minRequest.get('ERP/File/GetAccessoriesUrls?token='+Vue.prototype.$store.state.user?.AccessToken+'&id='+params.data);
		},
		//
		//例
		userPwdModify(params) {
			return minRequest.post('/post/user/pwd/modify', params)
		},
		// 项目审批列表
		listAuditProject() {
			return minRequest.get('/get/audit/project/list')
		},
		// 用户审批列表
		listAuditUser() {
			return minRequest.get('/get/audit/user/list')
		}
	},
}
